#include<bits/stdc++.h>
using namespace std;

int n,m;
unordered_set<string> s1,s2;
string s;

int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s;
        s1.insert(s);
    }
    cin>>m;
    for(int i=1;i<=m;i++){
        cin>>s;
        if(!s1.count(s)){
            cout<<"WRONG";
        }else if(s2.count(s)){
            cout<<"REPEAT";
        }else{
            cout<<"OK";
            s2.insert(s);
        }
        cout<<endl;
    }
    return 0;
}
